package ar.edu.itba.it.poo.dd.backend

import scala.Math._

trait FighterState
case object DEAD extends FighterState
case object ALIVE extends FighterState

abstract class Fighter(private var h: Int, private var s: Int) {
  private var state: FighterState = ALIVE

  def health = h
  def strength = s

  def fight(that: Fighter) {
    hurt(that.strength)
    if (isAlive) that.hurt(strength)
  }

  private def hurt(ammount: Int) {
    h = max(0, health - ammount)
    if (health == 0) state = DEAD
  }

  def heal(ammount: Int) = h = min(maxHealth, health + ammount)
  def isAlive = state == ALIVE

  // abstract members
  def level: Int
  def maxHealth: Int
}